package mysql

import "gorm.io/gorm"

type Order struct {
	gorm.Model
	UserId      int    `gorm:"type:int;comment:用户id"`
	OrderSn     string `gorm:"type:char(36);not null;index;comment:订单号"`
	PayType     int    `gorm:"type:tinyint(1);default:1;comment:支付类型:1:支付宝,2:微信"`
	PayTime     int    `gorm:"type:int;comment:支付时间"`
	Amount      int64  `gorm:"type:int;comment:订单金额"`
	OrderStatus int    `gorm:"type:tinyint(1);default:1;comment:订单状态:1:待支付, 2:已支付, 3:已发货, 4:已完成, 5:已取消"`
}

func (o *Order) Create() error {
	return Db.Create(&o).Error
}
func (o *Order) OrderInfo(orderId int64) error {
	return Db.Where("id = ?", orderId).Limit(1).Find(&o).Error
}

// 修改订单状态
func (o *Order) Update(orderSn string, orderStatus int) error {
	return Db.Debug().Model(&o).Where("order_sn = ?", orderSn).Update("order_status", orderStatus).Error
}
